home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 13358 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.8 KB

  1. Path: lrz-muenchen.de!news
  2. From: watzka@stat.uni-muenchen.de (Kurt Watzka)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Strange looking cast in lvalue
  5. Date: 6 Apr 1996 10:20:09 GMT
  6. Organization: Leibniz-Rechenzentrum, Muenchen (Germany)
  7. Distribution: world
  8. Message-ID: <4k5ggp$1mr@sparcserver.lrz-muenchen.de>
  9. References: <4k4s8q$3sv@nuscc.nus.sg>
  10. NNTP-Posting-Host: sun2.lrz-muenchen.de
  11.  
  12. eng30403@leonis.nus.sg (Tey Chee Meng) writes:
  13.  
  14. >(FARPROC)fnSnmpStrToOid=GetProcAddress(hinstWinSNMP,"_SNMPSTRTOOID");
  15.  
  16. >    Can anyone explain the effect, if any, of that (FARPROC) cast on the 
  17. >LHS of the expression ? fnSnmpStrToOid is a pointer to a function. 
  18.  
  19. And a cast expression is not an lvalue, so the expression does not
  20. make too much sense.
  21.  
  22. >GetProcAddress returns a pointer to a function as well but is of 
  23. >different type from fnSnmpStrToOid. Arent cast always used on the RHS of 
  24. >assignment expressions ?
  25.  
  26. Right! Well, in fact, casts _can_ be used in the LHS  of an assignment
  27. expression, if the LHS still renders an lvalue. Consider:
  28.  
  29.    struct foo
  30.    {
  31.       int fred;
  32.       char barney[10];
  33.    };
  34.  
  35.    void
  36.    set_fred(void *p)
  37.    {
  38.       ((struct foo *)p)->fred = 42;
  39.    }
  40.  
  41. In this case, we have a cast expression on the LHS of an assignment 
  42. operator, but the LHS still is an lvalue.
  43.  
  44. >    I found this code in the windows SDK help, but thought it is more 
  45. >a 'C' question than a windows question. Thanks.
  46.  
  47. A question does not come off-topic because it uses a certain API, if 
  48. the question is a question about the C programming language, not about
  49. the API.
  50.  
  51. OTOH, sometimes it is quite useful to avoid API functions if a potential
  52. responder will have to compile your code to answer your question, 
  53. because system or even API specific things might not be available
  54. to him/her.
  55.  
  56. Kurt
  57. --
  58. | Kurt Watzka                             Phone : +49-89-2180-6254
  59. | watzka@stat.uni-muenchen.de
  60.  
  61.